from student_model import *
from database import *


class StudentManager:  # 学生管理系统

    def add_student(self, sid, name, age, gender) -> None:  # 添加学生
        students = StudentModel(sid, name, age, gender)

        user_student.append(students.students)

    def delete_student(self, sid) -> None:  # 删除学生
        for item in user_student:
            if item["sid"] == sid:
                user_student.remove(item)

    def check_student(self, message):  # 查找学生
        found_student = []
        for item in user_student:
            if message in item["name"]:
                found_student.append(item)
        return found_student

    def correct_student(self, sid, name, age, gender) -> None:  # 修改学生
        for i in range(len(user_student)):
            if user_student[i]["sid"] == sid:
                user_student[i] = {"sid": sid, "name": name, "age": age, "gender": gender}

    def valid(self, sid, name, age, gender, boolean1):
        if type(sid) != int:
            if not sid.isdigit():
                return "学号只能数字"
        if name.isdigit():
            return "姓名不只是数字"
        if not age.isdigit():
            return "年龄只能数字"

        sid = int(sid)
        age = int(age)

        if boolean1:
            for item in user_student:
                if sid == item["sid"]:
                    return "学号重复"

        if age < 0 or age > 200:
            return "年龄的取值范围是(0,200)"
        if gender != "男" and gender != "女":
            return "性别只有男/女"

        return ""
